<?php
/**
 * 获取需要提醒的医嘱 模型
 * @authors xiadx (xiadx@zpdchina.com)
 * @date    2017-03-08 17:51:32
 * @version $Id$
 */

class ZhuyuanYizhuTixingInfoModel extends BaseModel {

	/**
     * 返回给终端的可执行sql语句的字段名称数组
     * @var [type]
     */
    public $_field_arr = ['yizhu_id','zhuyuan_id','yizhu_type','content','start_time','yongfa','yongliang','shiyong_danwei','pinlv','zuhao','yongfa_type','zhixing_state','state','wancheng_cishu'
    ];

    public function ls($user_department = '', $zhuyuan_ids = [])
    {
    	if (empty($zhuyuan_ids)) {
    		return [];
    	}
    	$set = Yaconf::get("config$this->yiyuan_id.xinyizhu_tixing_delete");
    	$field = 'yizhu_id,zhuyuan_id,yizhu_type,content,start_time,yongfa,yongliang,shiyong_danwei,pinlv,zuhao,yongfa_type,zhixing_state,state,wancheng_cishu';
    	$sql = DB::select($field)
    				->from('zhuyuan_yizhu_tixing_info')
    				->where('zhuyuan_id', 'IN', $zhuyuan_ids)
                    ->and_where("yiyuan_id","=",$this->yiyuan_id)
                    ->and_where("is_remind","=",0);
    	if($set['state'] == 'on'){
    		$sql->and_where('start_time', '>=', "DATE_SUB(now(),INTERVAL ".($set['value'] ?: 30)." MINUTE)");
    	}
        $query = $sql->execute()->as_array();
		return $query;
    }
}
